home *** CD-ROM | disk | FTP | other *** search
- Path: anvil.ugrad.cs.ubc.ca!not-for-mail
- From: c2a192@ugrad.cs.ubc.ca (Kazimir Kylheku)
- Newsgroups: comp.lang.c
- Subject: Re: Byte Orders and Char Sets?
- Date: 6 Mar 1996 15:11:50 -0800
- Organization: Computer Science, University of B.C., Vancouver, B.C., Canada
- Message-ID: <4hl63mINNdjb@anvil.ugrad.cs.ubc.ca>
- References: <4hkqm1$5dm@madeline.INS.CWRU.Edu>
- NNTP-Posting-Host: anvil.ugrad.cs.ubc.ca
-
- In article <4hkqm1$5dm@madeline.INS.CWRU.Edu>,
- Michael A. Balfour <mab22@po.CWRU.Edu> wrote:
- >
- >Hi!
- >
- >In the hopes of writing some portable code, I'm trying to
- >determine the byte order and character set that my program is
- >compiled in. Does anybody have a faster or cleaner way than
- >this:
- >
- >#define NativeCharSet() ((' '==0x40) ? EBCDIC_CHAR_SET : ASCII_CHAR_SET)
- >
- >static unsigned short int nativeIntTest=0x0001;
- >static char *nativeIntTest2=(char *)&nativeIntTest;
- >#define NativeByteOrder() ((nativeIntTest2[0]==0x00) ? LITTLE_ENDIAN : BIG_ENDIAN)
- >
- >(where the char sets and byte orders are also defined)
- >
- >Thank you very much,
-
- Why don't you pre-compute these values into global constants? NativeByteOrder()
- might not optimize away.
-
- You can write a separate program which performs these tests, and then generates
- a header file which you can include in another program. When installing your
- software, you compile the generator first, then run it to create the include
- file. This could be part of an automated ``make'' process or script.
-
- The include file will have simple manifest constants that tell you what
- character set you are using, etc. The advantage is that these can be edited
- manually, should there be a problem.
- --
-
-